package com.you.redis.pipeline;

import com.you.redis.practise.redpack.Basic;
import com.you.redis.util.JedisPoolsUtils;
import com.you.redis.util.JedisUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试redis指令的批量发送，非原子性
 */
public class RedisPipelineDemo {
    public static void main(String[] args) throws Exception {
        Jedis jedis = JedisUtils.getInstance().getJedis();
        Map<String, String> data = new HashMap<String, String>();
        // 使用pipeline hmset
        Pipeline pipe = jedis.pipelined();
        for (int i = 0; i < 10000; i++) {
            data.clear();
            data.put("k_" + i, "v_" + i);
            pipe.hmset("key_" + i, data); //将值封装到PIPE对象，此时并未执行，还停留在客户端
        }
        pipe.sync(); //将封装后的PIPE一次性发给redis
    }
}
